package cn.mujiankeji.mbrowser.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import cn.mujiankeji.mbrowser.数据.枚举类.主题颜色枚举
import cn.mujiankeji.mbrowser.数据.配置项.应用配置

private val DarkColorScheme = darkColorScheme(

    primary = Purple80,
    secondary = PurpleGrey80,
    tertiary = Pink80
)

private val LightColorScheme = lightColorScheme(
    primary = Purple40,
    secondary = PurpleGrey40,
    tertiary = Pink40,
    background = Color(0xfffafafa),
    surface = Color.White,
    surfaceContainer = Color(0xFFFFFFFF),
    surfaceVariant = Color(0xffF1F1F1),
    /*background = Color(0xfff1f2f3),
    surface = Color(0xFFFFFFFF),*/
    surfaceTint = Color(0xFF323232),
    onPrimary = Color.White,
    onSecondary = Color.White,
    onTertiary = Color.White,
    onBackground = Color(0xFF1C1B1F),
    onSurface = Color(0xFF1C1B1F),
)


@Composable
fun Mbrowser4Theme(
    // Dynamic color is available on Android 12+
    dynamicColor: Boolean = true,
    content: @Composable () -> Unit
) {

    val 主题颜色 = 应用配置.读取主题颜色().collectAsState(主题颜色枚举.跟随系统).value
    val isDarkTheme = if (主题颜色 == 主题颜色枚举.跟随系统) isSystemInDarkTheme()
        else 主题颜色 == 主题颜色枚举.深色

    val colorScheme = when {/*
        dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
            val context = LocalContext.current
            if (isDarkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
        }*/

        isDarkTheme -> DarkColorScheme
        else -> LightColorScheme
    }

    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography,
        content = content
    )
}